<?php
include_once(PATH_SQL . 'login_sql.php');
include_once(PATH_MODEL . 'login_model.php');
include_once(PATH_VIEW_ADMIN . 'login_view.php');
$oModel_login=new Model_Login();
$oView_login=new View_Admin_Login_Template($oModel_login);
if($_SERVER['REQUEST_METHOD']=="POST") {
    $oModel_login->setData('admin_username',$_POST['admin_username']);
    $oModel_login->setData('admin_password',$_POST['admin_password']);
    $check_login = $oModel_login->check_login();

    if(is_array($check_login)) {
        if($check_login['admin_status']==0) {
            $oModel_login->setErrorMsg($oModel_login->aLanguage['LOGIN']['alert_unactive']);
        }
        else {
            $_SESSION['admin_id'] 			= $check_login['admin_id'];
            $_SESSION['admin_username'] 	=       $check_login['admin_username'];
            $_SESSION['admin_role'] 		=       $check_login['admin_role'];

            $_SESSION['user_name']			=$check_login['admin_username'];
            $_SESSION['user_id']			= $check_login['admin_id'];
            $_SESSION['user_role']			=$check_login['admin_role'];
            /*
            if($check_login['admin_role']==1) {
                redir('index.php');
            }
            else {
                redir('?sMod=top_page');
            }
            */
            redir('?sMod=home');
        }
    }
    else {
        $oModel_login->setErrorMsg($oModel_login->aLanguage['LOGIN']['alert_login_fail']);
    }
}
$oView_login->displayPage($oModel_login);
